﻿@using Microsoft.AspNetCore.Components.Rendering
@inherits LayoutComponentBase
@inject GlobalConfig GlobalConfig

<AuthorizeView>
    <NotAuthorized>
        <MApp>
            <div style="height:100%;margin:0;padding:0;">
                <Masa.Framework.Admin.Web.Pages.Authentication.Login_v2></Masa.Framework.Admin.Web.Pages.Authentication.Login_v2>
            </div>
        </MApp>
    </NotAuthorized>
    <Authorized>
        <MApp>
            <MAppBar Elevation=0 App MaxHeight=60 Class="@($"{(GlobalConfig.PageMode == PageModes.PageTab ?"mx-6":"mx-6 rounded-b-4")}")">
                <Favorite NavHelper=NavHelper CurrentUri="@NavigationManager.Uri" />
                <MSpacer />
                <Search NavHelper=NavHelper />
                <MIcon Size=20 Class="ml-5" Color="neutral-lighten-3">mdi-message-processing-outline</MIcon>
                <MIcon Size=20 Class="ml-5" Color="neutral-lighten-3" OnClick="()=> _showSetting = true">mdi-cog</MIcon>
                <Language />
                <Login />
            </MAppBar>

            <Navigation />

            <MMain Class="fill-lighten-1" Style="padding-top:60px">
                @{
                    var uri = NavigationManager.Uri.Replace(NavigationManager.BaseUri, "");
                }
                @if (uri != "" && PermissionHelper.CheckMenuPermissionBuUrl(uri) is false && NavigationManager.Uri.Contains("/pages/others/401") is false)
                {
                    <Masa.Framework.Admin.Web.Pages.Others.NotAuthorized />
                }
                else
                {
                    if (GlobalConfig.PageMode == PageModes.Breadcrumb)
                    {
                        <div class="pa-6 max-width max-height">
                            <Breadcrumb NavHelper=NavHelper CurrentUri="@NavigationManager.Uri"></Breadcrumb>
                            @Body
                        </div>
                    }
                    else if (GlobalConfig.PageMode == PageModes.PageTab)
                    {
                        <PageTabs>
                            @Body
                        </PageTabs>
                    }
                    else
                    {
                        <div class="pa-6 max-width max-height">
                            @Body
                        </div>
                    }
                }
            </MMain>

            <Settings @bind-GlobalConfig=GlobalConfig @bind-Show=_showSetting />

            <MLoading />
            <MConfirmDialog />
            <MMessage />

            <MOverlay ZIndex=999 @bind-Value="_show">
                <MSnackbar Vertical Top Color="deep-purple accent-4" @bind-Value="_show" Timeout=-1>
                    <ChildContent>
                        @_msg
                    </ChildContent>
                    <ActionContent>
                        <MButton Color="red"
                                 Text
                                 OnClick="GoToLogout">
                            确定
                        </MButton>
                    </ActionContent>
                </MSnackbar>
            </MOverlay>
        </MApp>
    </Authorized>
</AuthorizeView>


@code {

    private bool? _showSetting;
}